// 1. 引入模块
import {
    createSlice, // 通过该函数创建数据状态管理模块
    configureStore // 生成仓库
} from '@reduxjs/toolkit'
import articleSlice from "@/store/article.store.ts";
// 2. 创建数据状态管理模块
const themeSlice = createSlice({
    name: 'theme',
    initialState: {
        flag: localStorage.getItem("mkTheme") === 'true'
    },
    reducers: {
        setTheme: (state, action) => {
            state.flag = action.payload
            // 将数据保存到本地
            localStorage.setItem("mkTheme", action.payload)
        }
    }
})
// 3. 生成仓库
export const store = configureStore({
    reducer: {
        theme: themeSlice.reducer,
        articles: articleSlice.reducer
    }
})
// 4. 导出模块
export const {
    setTheme
} = themeSlice.actions
export type AppDispatch = typeof store.dispatch
export default themeSlice.reducer